﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Arcana.Contract.Argument
{
    /// <summary>
    /// The base class for all argument contracts that perform comparisons.
    /// </summary>
    /// <remarks>
    /// <b>Note to implementers: </b> Proper roles should be applied by each implementing class. See
    /// <see cref="Roles"/> for more information on this topic. Also, the argument value MUST be obtained through
    /// <see cref="ContractBase.GetArgument"/> method.
    /// </remarks>
    [Serializable]
    public abstract class ComparingContractBase : ContractBase, IComparerContract
    {
        private System.Collections.IComparer _comparer;

        /// <summary>
        /// Initializes a new instance of <b>ComparingContractBase</b>.
        /// </summary>
        /// <param name="parameterName">The parameter name to which argument contract applies.</param>
        /// <exception cref="ArgumentNullException"><i>parameterName</i> is <b>null</b>.</exception>
        public ComparingContractBase(string parameterName) : base(parameterName)
        {
            _comparer = System.Collections.Comparer.Default;
        }

        /// <summary>
        /// Represents the comparer used to compare values.
        /// </summary>
        /// <value>The comparer to use when comparing values to check contract validity.</value>
        /// <remarks>
        /// This property is by default set to <see cref="System.Collections.Comparer.Default"/>.
        /// </remarks>
        /// <exception cref="System.ArgumentNullException"><i>value</i> is <b>null</b>.</exception>
        public System.Collections.IComparer Comparer
        {
            get
            {
                return _comparer;
            }
            set
            {
                if (value == null) throw new ArgumentNullException();
                _comparer = value;
            }
        }
    }
}
